package com.woniu.his.controller;


import com.woniu.his.dao.MedicalInfoMapper;
import com.woniu.his.entity.*;
import com.woniu.his.service.IDocterInfoService;
import com.woniu.his.service.IOperationInfoService;
import com.woniu.his.service.IPayInfoService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TATO
 * @since 2019-11-25
 */
@Controller
public class OperationInfoController {
    @Autowired
    private IOperationInfoService operationInfoService;
    @Autowired
    private MedicalInfoMapper medicalInfoMapper;
    @Autowired
    private IDocterInfoService docterInfoService;
    @Autowired
    private IPayInfoService payInfoService;

    @RequiresRoles("手术部")
    @RequestMapping("/operation-section")
    public String jpMain() {
        return "operation-section";
    }
    @RequiresRoles("手术部")
    @RequestMapping("/operation-apply")
    public String jpApply() {
        return "operation-apply";
    }
    @RequiresRoles("手术部")
    @RequestMapping("/operation-equipment")
    public String jpEquip() {
        return "operation-equipment-apply";
    }
    @RequiresRoles("手术部")
    @RequestMapping("/operation-drug")
    public String jpDrug() {
        return "operation-drug-apply";
    }
    @RequiresRoles("手术部")
    @RequestMapping("getOperationInfoByOperationId")
    @ResponseBody
    public OperationDetailInfo getOperationInfoByOperationId(int operationId) {
        OperationDetailInfo operationInfo = operationInfoService.getOperationInfoByOperationId(operationId);
        System.out.println(operationInfo);
        return operationInfo;
    }
    @RequiresRoles("手术部")
    @RequestMapping("getOperationDetailInfoList")
    @ResponseBody
    public List<OperationDetailInfo> getOperationInfoList() {
        List<OperationDetailInfo> operationDetailInfoList = operationInfoService.getOperationInfoList();
        System.out.println(operationDetailInfoList);
        return operationDetailInfoList;
    }
    @RequiresRoles("手术部")
    @RequestMapping("getOperationInfoByMedicalId")
    @ResponseBody
    public List<OperationDetailInfo> getOperationInfoByMedicalId(int medicalId) {
        List<OperationDetailInfo> operationInfoList = operationInfoService.getOperationInfoByMedicalId(medicalId);
        return operationInfoList;
    }
    @RequiresRoles("手术部")
    @RequestMapping("deleteOperationInfoByOperationId")
    @ResponseBody
    public String deleteOperationInfoByOperationId(int operationId) {
        System.out.println("go");
        int result = operationInfoService.deleteOperationInfoByOperationId(operationId);
        return result + "";
    }
    @RequiresRoles("手术部")
    @PostMapping(value = "updateOperationInfoByOperationId")
    @ResponseBody
    public String updateOperationInfoByOperationId(int medicalId,int operationId, String operationType, String operationName, int docterId, Date operationTime) {
        int result = operationInfoService.updateOperationInfoByOperationId(medicalId,operationId, operationType, operationName, docterId, operationTime);
        return result + "";
    }

    @RequiresRoles("手术部")
    @RequestMapping("updateOperationPayByOperationId")
    @ResponseBody
    public String updateOperationPayByOperationId(int operationId, int isPay) {
        int result = operationInfoService.updateOperationPayByOperationId(operationId, isPay);
        return "" + result;
    }
    @RequiresRoles("手术部")
    @RequestMapping("updateOperationHandleByOperationId")
    @ResponseBody
    public String updateOperationHandleByOperationId(int operationId, int isHandle) {
        int result = operationInfoService.updateOperationHandleByOperationId(operationId, isHandle);
        return "" + result;
    }
    @RequiresRoles("手术部")
    @RequestMapping("updateOperationActionByOperationId")
    @ResponseBody
    public String updateOperationActionByOperationId(int operationId, int isAction) {
        int result = operationInfoService.updateOperationActionByOperationId(operationId, isAction);
        return "" + result;
    }
    @RequiresRoles("手术部")
    @RequestMapping("selectDocterBySectionId")
    @ResponseBody
    public List<DocterInfo> selectDocterBySectionId(int sectionId) {
        List<DocterInfo> docterInfoList = docterInfoService.findDoctersBySectionId(sectionId);
        return docterInfoList;
    }

    @RequiresRoles("手术部")
    @PostMapping("showPatientDetailByOperationId")
    @ResponseBody
    public OperationAllDetailInfo showPatientDetailByOperationId(int operationId, int medicalId) {
        return operationInfoService.showPatientDetailByOperationId(operationId, medicalId);
    }

    @RequiresRoles("手术部")
    @PostMapping("getDrugInfo")
    @ResponseBody
    public List<DrugInfo> getDrugInfo() {
        return operationInfoService.getDrugInfo();
    }
    @RequiresRoles("手术部")
    @PostMapping("getEquipmentInfo")
    @ResponseBody
    public List<EquipmentInfo> getEquipmentInfo() {
        return operationInfoService.getEquipmentInfo();
    }


    @RequiresRoles("手术部")
    @PostMapping("addPayInfo")
    @ResponseBody
    public String addPayInfo(@RequestBody List<Map<String, Object>> payList) {
        return operationInfoService.addPayInfo(payList);

    }

    @RequiresRoles("手术部")
    @PostMapping("mainPageLoad")
    @ResponseBody
    public OperationPeopleInfo mainPageLoad(){
        return operationInfoService.mainPageLoad();
    }

    @RequiresRoles("手术部")
    @PostMapping("getOperationInfoByAction")
    @ResponseBody
    public List<OperationDetailInfo> getOperationInfoByAction(){
        return operationInfoService.getOperationInfoByAction();
    }

}

